package cn.baddonkey.superquery.controller;

import cn.baddonkey.superquery.response.CommonResult;
import cn.baddonkey.superquery.service.ModuleQueryConfigService;
import cn.baddonkey.superquery.vo.ModuleQueryConfigVo;
import cn.baddonkey.superquery.vo.ModuleQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/moduleQueryConfig")
public class ModuleQueryConfigController {

    @Autowired
    private ModuleQueryConfigService moduleQueryConfigService;

    @GetMapping("/detail")
    public CommonResult<ModuleQueryConfigVo> detail(@RequestParam("id") Long id,
                                                    @RequestParam(required = false) Long versionId) {
        ModuleQueryConfigVo detail = moduleQueryConfigService.detail(id, versionId);
        return CommonResult.success(detail);
    }

    @PostMapping("/save")
    public CommonResult<Void> add(@RequestBody ModuleQueryConfigVo vo) {
        moduleQueryConfigService.add(vo);
        return CommonResult.success();
    }

    @GetMapping("/listVersion")
    public CommonResult<Page<ModuleQueryVo>> listVersion(@RequestParam("id") Long id,
                                                         @RequestParam("pageNum") Integer pageNum,
                                                         @RequestParam("pageSize") Integer pageSize) {
        Page<ModuleQueryVo> moduleQueryVoPage = moduleQueryConfigService.listVersion(id, pageNum, pageSize);
        return CommonResult.success(moduleQueryVoPage);
    }

}
